import { defineStore } from 'pinia'


const uniStorage = {
  setItem (key, state) {
     return  uni.setStorageSync(key,state) //Cookies.set('accessToken', state.accessToken, { expires: 3 })
  },
  getItem (key) {
	  return uni.getStorageSync(key)
  }
}

export const useChatStore = defineStore('chatStore',{
	state(){
		return {
			topics: {}
		}
	},
	getters:{
		topic(topic) {
			return this.topics[topic]
		}
	},
	actions:{
		push(topic,message)
		{
			if(!this.topics[topic])
				this.topics[topic] = []
			
			this.topics[topic].push(topic)
		},
		clean(){
			this.topics = {}
		}
	},
	// persist: {
	//     enabled: true,
	//     strategies: [
	// 		{
	// 			key: 'chat-storage',
	// 			storage:uniStorage
	// 		}
	// 	], // <- HERE
	// }
})